home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 48971 / 48971.xpi / content / gview.js < prev    next >
Text File  |  2010-02-10  |  2KB  |  31 lines

  1. var gview = {
  2.     go : function(url) {
  3.         var _valid = /.*(:\/\/.+\/.*\.(?:pdf|ps|ppt|doc|docx|tif|tiff)).*/i.test(url),
  4.          _open = function(url){
  5.             var _proto, _special;
  6.             // For Quick View in google.com and google.com.hk
  7.             if ((_special = /^https?:\/\/[^\.]+\.google\.com?\.?[^\/]*\/url\?.*url=([^&]+)/i.exec(url)
  8.                  || /^https?:\/\/[^\.]+\.google\.com?\.?[^\/]*\/url\?.*q=([^&]+)/i.exec(url))
  9.                  && (url = decodeURIComponent(_special[1])) && /\/\/docs\.google\.com\//i.test(url)) {
  10.                  _special = /cache:[^:]+:([^\+]+)/i.exec(url);
  11.                 url = url.replace(/^https?/, (_special[1].indexOf('https') === 0) ? 'https' : 'http');
  12.             } else {
  13.                 url = (_special = /^https?:\/\/(?:docs\.google\.com\/g?viewe?r?|www\.google\.com?\.?[^\/]*\/url)\?.*url=([^&]*)/i.exec(url))
  14.                     ? _special[1]
  15.                     : encodeURIComponent(url);
  16.                 _proto = /^([^%]*)%3A/i.exec(url);
  17.                 url = (!_proto || 'http'==_proto[1] ? 'http' : 'https') + '://docs.google.com/viewer?url=' + url;
  18.             }
  19.  
  20.             var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(''),
  21.                 newWin = prefManager.getBoolPref('extensions.gview.openboolpref', false);
  22.  
  23.             if (newWin)
  24.                 window.open(url, '', "width=780,height=450,location=yes,resizable=yes,scrollbars=yes,status=yes")
  25.             else
  26.                 gBrowser.selectedTab = gBrowser.addTab(url)
  27.          };
  28.         if (_valid || window.confirm('Only PDF documents, PowerPoint presentations, and TIFF files are supported!\nStill go ahead?'))
  29.             _open(url)
  30.     }
  31. }